<?php
// +----------------------------------------------------------------------
// | Copyright (c) 2018-2018 http://www.donglixia.net All rights reserved.
// +----------------------------------------------------------------------
// | Author: 十万马 <962863675@qq.com>
// +----------------------------------------------------------------------
// | DateTime: 2018-02-09 16:17
// +----------------------------------------------------------------------

namespace app\index\controller;

use app\index\model\Article;
use think\Request;

class College extends Base
{
    public function __construct(Request $request = null)
    {
        parent::__construct($request);
        $this->currentModel = new Article();//实例化当前模型
    }

    /**
     * 学院介绍
     * @return mixed
     */
    public function college()
    {
        $this->renderData(7);//渲染数据，分类cat_id：学院介绍
        return $this->fetch();
    }

    /**
     * 课程表
     * @return mixed
     */
    public function collegeK()
    {
        $this->renderData(11);//渲染数据，分类cat_id：课程表
        return $this->fetch();
    }

    /**
     * 师资介绍
     * @return mixed
     */
    public function collegeS()
    {
        $this->renderData(8);//渲染数据，分类cat_id：师资介绍
        return $this->fetch();
    }

    /**
     * 课程介绍
     * @return mixed
     */
    public function collegeW()
    {
        $this->renderData(10);//渲染数据，分类cat_id：课程介绍

        //WSET介绍：简介
        $wset_data = $this->currentModel->getDataList(['cat_id'=>43]);
        $this->assign('wset_data', $wset_data);

        //WSET介绍：列表
        $wset_list = $this->currentModel->getDataList(['cat_id'=>46]);
        $this->assign('wset_list', $wset_list);

        //HPWS介绍：简介
        $hpws_data = $this->currentModel->getDataList(['cat_id'=>44]);
        $this->assign('hpws_data', $hpws_data);
        return $this->fetch();
    }

    /**
     * 葡萄酒小知识
     * @return mixed
     */
    public function collegeZ()
    {
        $this->renderData(12);//渲染数据，分类cat_id：葡萄酒小知识
        return $this->fetch();
    }

    /**
     * 专业资质
     * @return mixed
     */
    public function collegeZz()
    {
        $this->renderData(9);//渲染数据，分类cat_id：专业资质
        return $this->fetch();
    }

    /**
     * 详情页
     * @return mixed
     */
    public function detail()
    {
        $param = $this->request->param();
        $art_id = !empty($param['art_id']) ? $param['art_id'] : 0;
        $data = $this->currentModel->getArticleInfo(['art_id'=>$art_id]);
        $this->assign('data', $data);
        if (empty($data)) {
            return $this->fetch(STATIC_PATH.'/404.html');
        }

        return $this->fetch();
    }

    /**
     * 渲染数据，公共方法
     * @param $cat_id int 按分类id搜索
     */
    public function renderData($cat_id = 0)
    {
        $cat_list = $this->currentModel->getCatList(['cat_type'=>207, 'pid'=>0]);//获取版块(葡萄酒学院)下的分类列表
        foreach ($cat_list as $k=>$v) {
            $cat_list[$k]['is_display'] = $v['cat_id'] == $cat_id ? 1 : 0;//标记当前分类，前端显示
            switch ($v['cat_id']) {
                case 7 :
                    $cat_list[$k]['link'] = url('college');//学院介绍
                    break;
                case 11 :
                    $cat_list[$k]['link'] = url('collegeK');//课程表
                    break;
                case 8 :
                    $cat_list[$k]['link'] = url('collegeS');//师资介绍
                    break;
                case 10 :
                    $cat_list[$k]['link'] = url('collegeW');//课程介绍
                    break;
                case 12 :
                    $cat_list[$k]['link'] = url('collegeZ');//葡萄酒小知识
                    break;
                case 9 :
                    $cat_list[$k]['link'] = url('collegeZz');//专业资质
                    break;
                default:
                    $cat_list[$k]['link'] = '';
                    break;
            }
        }
        $this->assign('cat_list', $cat_list);

        $data_list = $this->currentModel->getDataList(['cat_id' => $cat_id]);//获取分类下的数据列表
        $this->assign('data_list', $data_list);

        //获取banner
        $banner = $this->currentModel->getBanner('banner', 'AE');
        $this->assign('banner', $banner);

        $this->assign('web', ['title' => '葡萄酒学院']);//网站标题
    }

}

